package com.htg.util;

import android.content.res.Resources;
import android.view.View;
import android.view.ViewGroup;


public class UtilBar {


    public static void addMarginBottomEqualNavBarHeight(View view) {
        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        layoutParams.setMargins(layoutParams.leftMargin,
                layoutParams.topMargin ,
                layoutParams.rightMargin,
                layoutParams.bottomMargin+ getNavBarHeight());
        view.setLayoutParams(layoutParams);
    }


    public static void addMarginLeftEqualNavBarHeight(View view) {
        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        layoutParams.setMargins(layoutParams.leftMargin+ getNavBarHeight(),
                layoutParams.topMargin ,
                layoutParams.rightMargin,
                layoutParams.bottomMargin);
        view.setLayoutParams(layoutParams);
    }

    public static void addMarginRightEqualNavBarHeight(View view) {
        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        layoutParams.setMargins(layoutParams.leftMargin,
                layoutParams.topMargin ,
                layoutParams.rightMargin+ getNavBarHeight(),
                layoutParams.bottomMargin);
        view.setLayoutParams(layoutParams);
    }

    public static int getNavBarHeight() {
        Resources res = Resources.getSystem();
        int resourceId = res.getIdentifier("navigation_bar_height", "dimen", "android");
        if (resourceId != 0) {
            return res.getDimensionPixelSize(resourceId);
        } else {
            return 0;
        }
    }
}
